package com.atguigu.lease.web.admin.custom.converter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/**
 * @Author 快点干早点散
 * @Create 2025/3/27 13:52
 * Description:
 */
@Component//注入容器
public class StringToItemTypeConverter implements Converter<String, ItemType>{


    @Override
    public ItemType convert(String code) {
      //values 获取枚举所有值
        ItemType[] values = ItemType.values();
        for (ItemType value : values) {
            if (code.equals(value.getCode()+"")){
                return  value;
            }
        }
         throw new RuntimeException("类型输入错误!!!只能输入1或2");
    }
}
